package pers.whj;

import pers.whj.sort.SortException;
import pers.whj.sort.number.NumSort;

import java.io.IOException;
import java.util.Random;
import java.util.Scanner;

public class Test {
    static Random ran = new Random();
    static final int SIZE = 100000;
    static int[] array = new int[SIZE];

    public static void main(String[] args) throws IOException, SortException {
        int counts = 0;
        long start = System.currentTimeMillis();
        for (int i = 1; i <= 10000000; i++) {
            if (IsPrimeNumber(i)) {
                counts++;
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("spend time: " + (end - start));
        System.out.println("共有素数" + counts + "个");
    }

    public static int RandomNum(int max) {
        return ran.nextInt(max);
    }

    public static boolean IsPrimeNumber(int num) {
        if (num <= 1) {
            return false;
        }
        if (num == 2) {
            return true;
        }
        if (num % 2 == 0) {
            return false;
        }
        int limit = (int) Math.sqrt(num);
        for (int i = 3; i <= limit; i += 2) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}